package com.wzx.ptplatform.service.impl;

import com.wzx.ptplatform.dao.ResumeDao;
import com.wzx.ptplatform.domain.Resume;
import com.wzx.ptplatform.service.ResumeService;
import com.wzx.ptplatform.utils.PageUtils;
import com.wzx.ptplatform.utils.PtplatformException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 紫煦桉
 */
@Service
public class ResumeServiceImpl implements ResumeService {

    @Resource
    private ResumeDao resumeDao;

    @Override
    public Page<Resume> findList(Integer page, Integer limit) throws PtplatformException {
        PageRequest pageable = PageUtils.setPageable(page, limit);
        return resumeDao.findAll(pageable);
    }

    @Override
    public Resume findById(long id) throws PtplatformException {
        return resumeDao.findById(id).orElse(null);
    }

    @Override
    public boolean saveOrEdit(Resume resume) throws PtplatformException {
        try {
            resumeDao.saveAndFlush(resume);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean deleteById(long id) throws PtplatformException {
       try {
           resumeDao.deleteById(id);
           return true;
       } catch (Exception e) {
           e.printStackTrace();
           return false;
       }
    }
}
